package com.chushouya.controller.manager.admin;


import com.chushouya.common.constant.ServiceType;
import com.chushouya.common.support.Contexts;
import com.general.framework.core.lang.Longs;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.chushouya.manager.dto.admin.user.UserListDTO;
import com.chushouya.manager.dto.admin.user.query.UserQuery;
import com.chushouya.manager.service.admin.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = ServiceType.PLATFORM + "用户管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/user")
public class UserController {

    @Resource
    private UserService userService;
    /**
     * 获取用户列表
     */
    @ApiOperation("查询用户列表")
    @GetMapping("/page")
    public Response<PageResult<UserListDTO>> list(UserQuery query) {
        final Long partnerId = Contexts.getUserContext().getPartnerId();
        if(Longs.notNullAndZero(partnerId)) {
            query.setPartnerId(partnerId);
        }
        return Response.success(userService.selectUserPageResult(query));
    }

    /**
     * 切换用户状态
     */
     @ApiOperation("切换用户状态")
     @PostMapping("/toggleStatus")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "userId", value = "用户Id", dataType = "Long", paramType = "query"),
             @ApiImplicitParam(name = "status", value = "用户状态", dataType = "status", paramType = "query")
     })
     public Response<Boolean> toggleStatus(Long userId,Integer status) {
         userService.toggleStatus(userId, status);
         return Response.success();

     }

}
